#ifndef __LOGO_PARSE_H__
#define __LOGO_PARSE_H__

#include <stdio.h>
#include <stdlib.h>
#include "scan.h"
#include "logo_lib.h"

#ifdef __cplusplus
extern "C" 
{
#endif /*  __cplusplus */



#define TRUE 1
#define FALSE 0
#define MAX_CHILDREN 4
#define UNKNOW_STR "--UNKNOW--"

#define CHECK_MEM(x) do { \
                        if (!x) { \
                           print_info (ERROR_INFO, \
                                    "Cannot allocate memory. at %s, %d\n", \
                                    __FILE__, __LINE__); \
                           exit (-1); \
                        } \
                     } while (0)


extern int g_syntax_error;

typedef enum {
   ExpNode, StmtNode
} node_type_t;

typedef enum {
   ConstExp, OpExp, IdExp, StrExp, RtnExp
} exp_type_t;

struct tag_tree_node;

typedef struct tag_tree_node {
   struct tag_tree_node* sibling;
   struct tag_tree_node* child[MAX_CHILDREN];
   int   line_no;
   node_type_t       node_type;
   union {
      exp_type_t     exp;
      token_t        stmt;
   } type;
   union {
      token_t        op; /* this is token */
      double         val;
      char*          id_str;
      char*          str_val;
   } attr;
} tree_node_t;


void init_tree_node (tree_node_t* node);
void delete_tree_node (tree_node_t* node);
void delete_tree (tree_node_t* root);
char* copy_string (const char* src);
void print_parse_tree_node (tree_node_t* node);

const tree_node_t* get_rightmost_node(const tree_node_t* tree);

#ifdef __cplusplus
}
#endif /*  __cplusplus */

#endif /* __LOGO_PARSE_H__ */
